/**************************************************************************************
*
*	Copyright (C) 2009 Brent Andrew Chua - See LICENSE.txt for more info.
*		
*	Filename	-	Bitmap.h
*
*	Description -	Basic bitmap class for rendering bitmap objects.
*
*	Comments	-	If you don't understand some part of the code, use MSDN!!!
*						Move the cursor to the function/type then hit F1 in VS.
*
*	Modification History:
*			Name			   Date					Description
*			CodeSushi	-	11/17/2009	-	Creation of this file
**************************************************************************************/

#ifndef _BITMAP_H_
#define _BITMAP_H_

#include <windows.h>
#include "../../Pulse Lib/Include/Pulse.h"

using namespace Pulse;

class Bitmap
{
public:

	// Type of bitmap
	enum BitmapType { TYPE_BITMAP, TYPE_MASKED_BITMAP, TYPE_TRANSPARENT_BITMAP, TYPE_ROTATION_BITMAP, NUM_BITMAP_TYPES };

	// On what offset does the bitmap needs to be rendered.
	enum PositionType { POS_UPPER_LEFT, POS_CENTER, NUM_POSITION_TYPES };
	
	// Basic blending options
	enum BlendOptions { BLEND_ALL_WHITE = WHITENESS, BLEND_ALL_BLACK = BLACKNESS, BLEND_AND = SRCAND, 
		BLEND_DEST_INVERT = DSTINVERT, BLEND_SRC_COPY = SRCCOPY, BLEND_XOR = SRCINVERT, BLEND_OR = SRCPAINT,
		BLEND_INVERT_SRC = NOTSRCCOPY, BLEND_INVERT_SRC_AND = SRCERASE, BLEND_MERGE_PAINT = MERGEPAINT, 
		NUM_BLEND_OPTIONS };

	Bitmap( HINSTANCE hAppInst, const CHAR *pImageFileName, const PositionType posType = POS_UPPER_LEFT, const BlendOptions bOp = BLEND_SRC_COPY );
	virtual ~Bitmap( void );

	LONG GetWidth( void ) const;
	LONG GetHeight( void ) const;

	void SetBlendOption( const BlendOptions blendOp );
	BlendOptions GetBlendOptions( void ) const;

	void SetPositionType( const PositionType type );
	PositionType GetPositionType( void ) const;

	virtual const BitmapType GetType( void ) const;

	virtual void Render( HDC hBBDC, HDC hSprDC, INT x, INT y );
	virtual void Render( HDC hBBDC, HDC hSprDC, INT x, INT y, INT w, INT h, INT srcX, INT srcY );
	virtual void Render( HDC hBBDC, HDC hSprDC, RECT dest, INT srcX, INT srcY );

	// Collision Check
	virtual Pulse::BOOL TestPoint( INT x, INT y );

protected:

	void TranslatePosition( INT &x, INT &y );

	// We probably need to implement this but just hide this for now
	Bitmap & operator = ( const Bitmap &rhs );

	HBITMAP			m_hBitmap;	// Handle to bitmap
	BITMAP			m_bmInfo;	// Bitmap Info
	PositionType	m_posType;	// Position type from what position will the image be rendered.
	BlendOptions	m_blendOp;	// How will this image be rendered. See BlendOptions. See MSDN for windows specific values.

};

PSX_INLINE LONG Bitmap::GetWidth( void ) const
{
	return m_bmInfo.bmWidth;
}

PSX_INLINE LONG Bitmap::GetHeight( void ) const
{
	return m_bmInfo.bmHeight;
}

PSX_INLINE void Bitmap::SetBlendOption( const BlendOptions blendOp ) 
{
	m_blendOp = blendOp;
}

PSX_INLINE Bitmap::BlendOptions Bitmap::GetBlendOptions( void ) const
{
	return m_blendOp;
}

PSX_INLINE void Bitmap::SetPositionType( const PositionType type ) 
{
	m_posType = type;
}

PSX_INLINE Bitmap::PositionType Bitmap::GetPositionType( void ) const
{
	return m_posType;
}

PSX_INLINE const Bitmap::BitmapType Bitmap::GetType( void ) const
{
	return TYPE_BITMAP;
}

PSX_INLINE void Bitmap::Render( HDC hBBDC, HDC hSprDC, RECT dest, INT srcX, INT srcY )
{
	Render( hBBDC, hSprDC, dest.left, dest.top, dest.right - dest.left, dest.bottom - dest.top, srcX, srcY );
}

#endif /* _BITMAP_H_ */